﻿using Microsoft.Extensions.Caching.Distributed;
using System.Text.Json;

namespace WhutDoomCheck.Server.Extentions
{
    public static class DistributedCacheExtension
    {
        public static TValue? Get<TValue>(this IDistributedCache cache, string key)
        {
            var json = cache.GetString(key);
            if (string.IsNullOrEmpty(json)) return default;
            return JsonSerializer.Deserialize<TValue>(json);
        }
            
        public static void Set<TValue>(this IDistributedCache cache, string key, TValue value)
        {
            var json = JsonSerializer.Serialize(value);
            cache.SetString(key, json);
        }
    }
}
